home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2506 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: alibaba.kmit.sk!not-for-mail
  2. From: brano@alibaba (Brano Zahradnik)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Question about destructor...
  5. Date: 18 Jan 1996 03:16:13 +0100
  6. Organization: Kmit
  7. Message-ID: <4dkahd$lv9@alibaba.kmit.sk>
  8. References: <4ce9mk$atg@eng_ser1.erg.cuhk.hk> <4cqrei$par@isoit109.bbn.hp.com>
  9. NNTP-Posting-Host: sk2eu.eunet.sk
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Manfred_Lange (Manfred_Lange@bbn.hp.com) wrote:
  13. : ywleung@cs.cuhk.hk (Marty McFly) wrote:
  14. : >Dear All,
  15. : >
  16. : >    I now have 2 classes A and B.  B is a derived class of A.  However,
  17. : >the internal implementation of A is not known, i.e., the private members of
  18. : >class A are not provided, only the public members are given.  But class B is 
  19. : >implemented by myself.  So what should be written in the destructor of B so 
  20. : >that all the private members inherited from A are also "deleted"?
  21. : >
  22. : >Regards,
  23. : >Marty McFly.
  24. : >
  25. : >
  26.  
  27. : Do you plan to go to the "Dance under the sea"?
  28.  
  29.  
  30. : I saw all the answers you got for your question. It is true, that you don't have 
  31. : to care for the destructor in the baseclass.
  32.  
  33. : But there is another aspect of the problem, that is important to know. Take the 
  34. : following sample:
  35.  
  36. : class Base
  37. : {
  38. :    ~Base();
  39. : };
  40.  
  41. : class Derived : public Base
  42. : {
  43. :    ~Derived();
  44. : };
  45.  
  46. : ..
  47.  
  48. : {  Base*   aBase;
  49.  
  50. :    aBase = new Derived();
  51.  
  52. :    ...
  53.  
  54. :    delete aBase;
  55.  
  56. : ..
  57.  
  58.  
  59. : Which destructor will be called when executing "delete aBase()" ?
  60.  
  61. I think, that destructors are calling in reverse order than constructors.
  62. In this example: ~Derived,~Base
  63.  
  64. Q: Why you need rewrite destructor of base ??
  65.  
  66.